import { jsbridge, getCCTVJsApi } from './cctvJsApi'
/**
 *currentNetworkState<Number> 0-'无网络'，1-移动网络，2-wifi
 *
 */
export const currentNetworkStateChange = function (state, isKingCard) {
	console.log('currentNetworkStateChange', state)
	if (state === 1) {
		if (isKingCard) {
			jsbridge.toast('您正在享受免流服务')
		} else {
			jsbridge.toast('您正在使用移动流量播放')
		}
	}
}

async function getKingCardInfoType () {
	const res = await jsbridge.bridgeInvoke('getKingCardInfoType')
	if (Number(res.errCode) === 0 && res.result.currentNetworkState !== 1) {
		return res.result
	}
	if (res.result.isKingCard) {
		jsbridge.toast('您正在享受免流服务')
	} else {
		jsbridge.toast('您正在使用移动流量播放')
	}
	return res.result
}

async function getKingCardInfo () {
	await getCCTVJsApi()
	return new Promise((resolve, reject) => {
		jsbridge.ready(async () => {
			const result = await getKingCardInfoType()
			resolve(result)
		})
	})
}

export default getKingCardInfo
